package process
import (
	"fmt"
	"go_code/projectExec2/common/message"
	"go_code/projectExec2/client/utils"
	"encoding/json"
)

type SmsProcess struct {

}

//发送群聊的消息
func (this *SmsProcess) SendGroupMes(content string)(err error){
	//1、创建一个Mes
	var mes message.Message
	mes.Type = message.SmsMesType
	
	//2、创建一个SmsMes实例
	var smsMes message.SmsMes
	smsMes.Content = content
	smsMes.UserId = CurUser.UserId
	smsMes.UserStatus = CurUser.UserStatus

	//3、对smsMes进行序列化
	data,err := json.Marshal(smsMes)
	if err != nil{
		fmt.Println("SendGroupMes json.Marshal_smsMes Error :",err)
		return
	}
	mes.Data = string(data)

	//4、对mes进行序列化
	data,err = json.Marshal(mes)
	if err != nil{
		fmt.Println("SendGroupMes json.Marshal_mes Error :",err)
		return
	}

	//5、将mes序列化后发送给服务器
	tf := &utils.Transfer{
		Conn : CurUser.Conn,
	}
	//6、发送
	err = tf.WritePkg(data)
	if err != nil{
		fmt.Println("SendGroupMes WritePkg_mes Error :",err)
		return
	}
	return 
}